FOREACH(i RANGE 0 14)
  SET(WIN64_MATLAB32 WIN64_MATLAB32-NOTFOUND CACHE INTERNAL "" FORCE)
  GET_FILENAME_COMPONENT(WIN64_MATLAB32 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\MathWorks\\MATLAB\\7.${i};MATLABROOT]" ABSOLUTE CACHE)  
  IF(NOT WIN64_MATLAB32 STREQUAL "/registry")
    SET(WIN64_MATLAB32_FOUND 1 CACHE INTERNAL "" FORCE)
    BREAK()
  ENDIF(NOT WIN64_MATLAB32 STREQUAL "/registry")
ENDFOREACH(i)

FOREACH(i RANGE 0 14)
  SET(WIN64_MATLAB64 WIN64_MATLAB64-NOTFOUND CACHE INTERNAL "" FORCE)
  GET_FILENAME_COMPONENT(WIN64_MATLAB64 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MathWorks\\MATLAB\\7.${i};MATLABROOT]" ABSOLUTE CACHE)
  IF(NOT WIN64_MATLAB64 STREQUAL "/registry")
    SET(WIN64_MATLAB64_FOUND 1 CACHE INTERNAL "" FORCE)
    BREAK()
  ENDIF(NOT WIN64_MATLAB64 STREQUAL "/registry")
ENDFOREACH(i)

IF(WIN64_MATLAB32_FOUND AND NOT WIN64_MATLAB64_FOUND)
  FILE(WRITE "testWin64Matlab32_TRUE.txt" "")
ELSEIF(WIN64_MATLAB32_FOUND AND WIN64_MATLAB64_FOUND)
  IF(WIN64_MATLAB32 STREQUAL WIN64_MATLAB64)
    FILE(WRITE "testWin64Matlab32_TRUE.txt" "")
  ENDIF(WIN64_MATLAB32 STREQUAL WIN64_MATLAB64)
ENDIF(WIN64_MATLAB32_FOUND AND NOT WIN64_MATLAB64_FOUND)